package com.canaan.system.service.impl;

import java.util.List;

import com.canaan.common.utils.DateUtils;
import com.canaan.system.mapper.ApiLogMapper;
import com.canaan.system.service.IApiLogService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.canaan.system.domain.ApiLog;
/**
 * Api日志记录Service业务层处理
 *
 * @author canaan
 * @date 2025-03-23
 */
@Service
public class ApiLogServiceImpl implements IApiLogService {
    @Resource
    private ApiLogMapper apiLogMapper;

    @Override
    public ApiLog selectApiLogByLogId(Long logId) {
        return  apiLogMapper.selectApiLogByLogId(logId);
    }

    /**
     * 查询Api日志记录列表
     *
     * @param apiLog Api日志记录
     * @return Api日志记录
     */
    @Override
    public List<ApiLog> selectApiLogList(ApiLog apiLog) {
        return apiLogMapper.selectApiLogList(apiLog);
    }

    /**
     * 新增Api日志记录
     *
     * @param apiLog Api日志记录
     * @return 结果
     */
    @Override
    public int insertApiLog(ApiLog apiLog) {
        apiLog.setLogTime(DateUtils.getNowDate());
        return apiLogMapper.insertApiLog(apiLog);
    }

    /**
     * 批量新增Api日志记录
     *
     * @param apiLogList Api日志记录列表
     * @return 结果
     */
    @Override
    public int batchInsertApiLog(List<ApiLog> apiLogList) {
        int insertNum = 0;
        for (ApiLog apiLog : apiLogList) {
            for (int i = 0; i < apiLogList.size(); ) {
                int endIndex = i + 500;
                if (endIndex > apiLogList.size()) {
                    endIndex = apiLogList.size();
                }
                insertNum = insertNum + apiLogMapper.batchInsertApiLog(apiLogList.subList(i, endIndex));
                i = endIndex;
            }
        }
        return insertNum;
    }
    /**
     * 修改Api日志记录
     *
     * @param apiLog Api日志记录
     * @return 结果
     */
    @Override
    public int updateApiLog(ApiLog apiLog) {
        return apiLogMapper.updateApiLog(apiLog);
    }

    /**
     * 批量修改Api日志记录
     *
     * @param apiLogList Api日志记录列表
     * @return 结果
     */
    @Override
    public int batchUpdateApiLog(List<ApiLog> apiLogList) {
        int updateNum = 0;
        for (ApiLog apiLog : apiLogList) {
            for (int i = 0; i < apiLogList.size(); ) {
                int endIndex = i + 500;
                if (endIndex > apiLogList.size()) {
                    endIndex = apiLogList.size();
                }
                updateNum = updateNum + apiLogMapper.batchUpdateApiLog(apiLogList.subList(i, endIndex));
                i = endIndex;
            }
        }
        return updateNum;
    }

}
